local jw_yanwei = fk.CreateSkill {
    name = "jw_yanwei",
    tags = { Skill.Limited },
}
Fk:loadTranslationTable {
    ["jw_yanwei"] = "燕威",
    [":jw_yanwei"] = "限定技，准备阶段，你可以选择至多体力值等量且有“炽”的角色，令这些角色随机分配共计X点火焰伤害，然后获得<a href='zhenxiao'>【震啸】</a>置入你的装备区(由此造成的伤害，无法为目标添加“炽”)。",
    ["zhenxiao"] = "震啸：持恒技，你可以将X张牌当做一张【杀】使用或打出(X为此技能的发动次数，至多为2)。",

    ["#jw_yanwei-ask"] = "燕威：你可以选择至多 %arg 名有“炽”的角色，对这些角色随机造成伤害。",

    ["$jw_yanwei1"] = "待吾先夺巴郡，再战江阳，分兵袭击，荡平西川！",
}
local U = require "packages/utility/utility"
jw_yanwei:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        local n = 0
        for _, i in ipairs(player.room.alive_players) do
            if i:getMark("@zhangfei_chi") > 0 then
                n = n + i:getMark("@zhangfei_chi")
            end
        end
        return target == player and player:hasSkill(jw_yanwei.name) and player.phase == Player.Start
            and player:usedSkillTimes(jw_yanwei.name, Player.HistoryGame) == 0 and n > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local ids = {}
        for _, i in ipairs(room:getOtherPlayers(player)) do
            if i:getMark("@zhangfei_chi") > 0 then
                table.insertIfNeed(ids, i)
            end
        end
        local tos = room:askToChoosePlayers(player, {
            targets = ids,
            min_num = 1,
            max_num = player.hp,
            prompt = "#jw_yanwei-ask:::" .. player.hp,
            skill_name = jw_yanwei.name,
            cancelable = true
        })
        if #tos > 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
        return false
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = event:getCostData(self).tos
        room:sortByAction(targets)
        local n = 0
        for _, i in ipairs(targets) do
            if i:getMark("@zhangfei_chi") > 0 then
                n = n + i:getMark("@zhangfei_chi")
            end
        end
        for _ = 1, n, 1 do
            local id = table.random(targets)
            if not id.dead then
                room:damage {
                    from = player,
                    to = id,
                    damage = 1,
                    skillName = jw_yanwei.name,
                    damageType = fk.FireDamage,
                }
            end
        end
        room:handleAddLoseSkills(player, "jw_zhenxiao")
    end,
})
return jw_yanwei
